package com.bupt.fmmall.service.Impl;

import com.bupt.fmmall.dao.OrderDao;
import com.bupt.fmmall.dao.ShoppingCartDao;
import com.bupt.fmmall.entity.SalesOrder;
import com.bupt.fmmall.entity.SalesOrderVO;
import com.bupt.fmmall.service.OrderService;
import com.bupt.fmmall.vo.ResultVO;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
@Service
public class OrderServiceImpl implements OrderService {
    @Resource
    OrderDao orderDao;
    @Resource
    ShoppingCartDao shoppingCartDao;
    @Override
    public ResultVO CusIncreaseOrder(String itemId,SalesOrder salesOrder) {
        String supplier=salesOrder.getSupplierUserName();
        String a[]=supplier.split(",");
        String arr[]=itemId.split(",");
        List<Integer> itemIds=new ArrayList<>();
        for (int i=0;i<arr.length;i++){
            salesOrder.setItemId(Integer.parseInt(arr[i]));
            salesOrder.setSupplierUserName(a[i]);
            salesOrder.setOrderStatusId(1);
            orderDao.insertOrder(salesOrder);
            itemIds.add(Integer.parseInt(arr[i]));
        }
        String name=salesOrder.getCustomerUserName();
        shoppingCartDao.delete_ShoppingCartGoods_by_userNameAndItemid(itemIds,name);
        return new ResultVO(200,"success",null);
    }

    @Override
    public void changeOrderState(SalesOrder salesOrder) {

    }

    @Override
    public List<SalesOrder> businessViewOrderStates(String supplierUserName) {
        return null;
    }

    @Override
    public ResultVO CusViewOrderStates(String customerUserName, Integer orderStatusId) {
        List<SalesOrderVO> list=orderDao.selectOrdersByNameAndState(customerUserName,orderStatusId);
        return new ResultVO(200,"success",list);
    }

    @Override
    public SalesOrder adminViewOrderState(int orderId) {
        return null;
    }

}
